package com.company.project.action;

import java.util.List;

import com.company.project.bean.GType;
import com.company.project.bean.Goods;
import com.company.project.service.AddGoodsService;
import com.company.project.service.GTService;
import com.company.project.service.GoodsService;
import com.company.project.service.STService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class GoodsAction extends ActionSupport implements ModelDriven<GType>{

	private static final long serialVersionUID = 1L;

	private GoodsService goodsService;
	private GTService gtService;
	private STService stService;
	private AddGoodsService agService;
	private List<?> list;
	private List<?> gtlist;
	private GType gtype = new GType();
	private Goods goods;
	private int id;
	private int totalPage=0;
	private int currentPage=1;
	private int rowTotal=0;
	private String[] goodspic;

	private List<?> list2;

	private List<?> selectlist;
	private String keywords;


	
	
	public String getKeywords() {
		return keywords;
	}
	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
	public List<?> getSelectlist() {
		return selectlist;
	}
	public void setSelectlist(List<?> selectlist) {
		this.selectlist = selectlist;
	}
	public String[] getGoodspic() {
		return goodspic;
	}
	public void setGoodspic(String[] goodspic) {
		this.goodspic = goodspic;
	}
	public int getRowTotal() {
		return rowTotal;
	}
	public void setRowTotal(int rowTotal) {
		this.rowTotal = rowTotal;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Goods getGoods() {
		return goods;
	}
	public void setGoods(Goods goods) {
		this.goods = goods;
	}
	public void setAgService(AddGoodsService agService) {
		this.agService = agService;
	}
	public GType getGtype() {
		return gtype;
	}
	public void setGtype(GType gtype) {
		this.gtype = gtype;
	}
	public void setStService(STService stService) {
		this.stService = stService;
	}
	public void setGtService(GTService gtService) {
		this.gtService = gtService;
	}
	public List<?> getGtlist() {
		return gtlist;
	}
	public void setGtlist(List<?> gtlist) {
		this.gtlist = gtlist;
	}
	public List<?> getList() {
		return list;
	}
	public void setList(List<?> list) {
		this.list = list;
	}
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	

	public List<?> getList2() {
		return list2;
	}
	public void setList2(List<?> list2) {
		this.list2 = list2;
	}
	
	
	public String list() {
		if(totalPage==0){
			totalPage = goodsService.getTotalPage(7);
		}
		if(totalPage==0){
			rowTotal = goodsService.getAllGoods().size();
		}
		if(currentPage<0){
			currentPage=1;
		}
		list = goodsService.getPage(currentPage);
		
		/*for(int i=0;i<list.size();i++){
			Goods g = (Goods) list.get(i);
			String[] pic = g.getGoodspic().substring(1).split(",");
			//((Goods) list.get(i)).setPicpath(pic);
			g.setPicpath(pic);
		}*/
		
		return "success";
	}
	
	//查询商品分类
	public String addgoodstype(){
		gtlist = gtService.getType();
		return SUCCESS;
	}
	
	//模糊查询
		public String select(){
			//goods = goodsService.findById(goods);
			
			 selectlist = goodsService.findByName(keywords);
			System.out.println(keywords);
			System.out.println(selectlist);
			return SUCCESS;
		}

	public String savetype(){	
		stService.savetype(gtype);	
		return SUCCESS;
		
	}
	
	public String typelist(){
		gtlist = gtService.getType();
		return SUCCESS;
	}
	
	public String addgoods(){
		gtlist = gtService.getType();
		return SUCCESS;
	}
	
	public String savegoods(){
		agService.addGoods(goods);
		return SUCCESS;
	}
	
	public String modifygoods(){
	goods=goodsService.find(goods.getId());
	gtlist = gtService.getType();
		return SUCCESS;
	}
	
	public String updategoods(){
		goodsService.save(goods);
		return SUCCESS;
	}

	
	@Override
	public GType getModel() {
		// TODO Auto-generated method stub
		return gtype;
	}
	
	
}
